package com.practice.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.practice.reggie.common.BaseContext;
import com.practice.reggie.common.R;
import com.practice.reggie.dto.OrdersQueryDTO;
import com.practice.reggie.entity.Orders;
import com.practice.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 用户下单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("订单数据：{}",orders);
        return R.success("下单成功");
    }


    /**
     * 用户付完钱后---查看用户订单功能 ------
     * http://localhost:8080/front/page/order.html
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page<Orders>> userPage(int page, int pageSize) {
        OrdersQueryDTO queryDTO = new OrdersQueryDTO();
        //查询当前登录用户订单列表
        queryDTO.setUserId(BaseContext.getCurrentId());
        return R.success(orderService.page(queryDTO, page, pageSize));
    }

    /**
     * 后台查询订单列表
     * @param queryDTO
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R<Page<Orders>> page(OrdersQueryDTO queryDTO, int page, int pageSize) {
        return R.success(orderService.page(queryDTO, page, pageSize));
    }
}